package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpSettleStyle;
import com.nuoniu.sibanyun.service.erp.IErpSettleStyleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 结算方式设置 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-10-12
 */
@RestController
@RequestMapping("/erp/settleStyle")
@Api(tags = "结算方式设置", value = "结算方式设置")
public class ErpSettleStyleController extends BaseController {

    @Autowired
    private IErpSettleStyleService settleStyleService;

    @GetMapping("pageList")
    @ApiOperation("获取列表")
    public HttpResult pageList(Page page, ErpSettleStyle settleStyle) {
        Page<ErpSettleStyle> settleStylePage = settleStyleService.pageList(page, settleStyle);
        return HttpResult.ok(settleStylePage);
    }

    @PostMapping("save")
    @ApiOperation("保存")
    public HttpResult save(@RequestBody ErpSettleStyle settleStyle) {
        if(StringUtils.isBlank(settleStyle.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }

        if(StringUtils.isBlank(settleStyle.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        settleStyleService.saveSettyleStyle(settleStyle);
        return HttpResult.ok();
    }

    @PostMapping("delete")
    @ApiOperation("删除")
    public HttpResult delete(@RequestBody List<Long> ids) {
        for(Long id : ids) {
            settleStyleService.removeById(id);
        }
        return HttpResult.ok();
    }
}
